local skel = fk.CreateSkill {
  name = "role_exmode_mingtu__lb_hu",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
  ["role_exmode_mingtu__lb_hu"] = "护",
  --[":role_exmode_mingtu__lb_hu"] = "<b>锁定技</b>，你的手牌上限+X（X为你的装备区牌数且至少为1）。",
  [":role_exmode_mingtu__lb_hu"] = "每回合限一次，当一名角色于回合内首次造成伤害时，你可以弃置一个区域的所有牌并防止之。",

  ["#role_exmode_mingtu__lb_hu"] = "护：你可以弃置一个区域的所有牌，防止 %src 即将对 %dest 造成的 %arg点%arg2伤害",
}
--[[
skel:addEffect("maxcards", {
  correct_func = function (self, player)
    if player:hasSkill(skel.name) then
      return math.max(#player:getCardIds("e"), 1)
    end
  end
})
--]]

skel:addEffect(fk.DetermineDamageCaused, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    local event_id = player.room.logic:getCurrentEvent().id
    local current = player.room:getCurrent()
    return player:hasSkill(skel.name) and target and current and current == target and not player:isAllNude() and
        (#player.room.logic:getEventsOfScope(GameEvent.Damage, 1, function(e)
          local damage = e.data
          return damage.from == target and e.id ~= event_id and not damage.prevented
        end, Player.HistoryTurn) == 0)
        and player:usedSkillTimes(skel.name) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local flag = { "h", "e", "j" }
    local all = { "$Hand", "$Equip", "$Judge" }
    local ask = {}
    for i, s in ipairs(flag) do
      if #table.filter(player:getCardIds(s), function(id)
            return not player:prohibitDiscard(id)
          end) > 0 then
        table.insert(ask, all[i])
      end
    end
    if #ask == 0 then return end
    table.insert(all, "Cancel")
    table.insert(ask, "Cancel")
    local choice = room:askToChoice(player, {
      choices = ask,
      all_choices = all,
      skill_name = skel.name,
      prompt = "#role_exmode_mingtu__lb_hu:" ..
      target.id .. ":" .. data.to.id .. ":" .. data.damage .. ":" .. Fk:getDamageNatureName(data.damageType),
    })
    if choice ~= "Cancel" then
      event:setCostData(self, { choice = flag[table.indexOf(all, choice)] })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    data:preventDamage()
    player:throwAllCards(event:getCostData(self).choice, skel.name)
  end,
})

return skel